import REGEXP_MAVEN from './reg-exp-maven';

export const isExternal = (path) => /^(https?:|mailto:|tel:)/.test(path);

export const isArray = (arg) => {
    if (typeof Array.isArray === 'undefined') {
        return Object.prototype.toString.call(arg) === '[object Array]';
    }
    return Array.isArray(arg);
};

// 去除首尾空格
export const clearStartAndEndEmpty = (str) => {
    return str ? str.trim() : str;
};
// 去除字符串中全部空格
export const clearEmpty = (str) => {
    return str ? str.replace(/\s+/g, '') : '';
};
// 检测特殊字符
export const checkSpecialStr = (str) => {
    return REGEXP_MAVEN.specialStr.test(str);
};
// 邮件检测
export const checkEmail = (email) => {
    return REGEXP_MAVEN.email.test(email);
};
// 电话检测
export const checkTel = (tel) => {
    return REGEXP_MAVEN.tel.test(tel);
};
// url检测
export const checkURL = (url) => {
    return REGEXP_MAVEN.url.test(url);
};
// 用户名检测
export const checkUserName = (str) => {
    return REGEXP_MAVEN.username.test(str);
};
// 密码检测
export const checkPassword = (str) => {
    return REGEXP_MAVEN.password.test(str);
};
// 检测验证码
export const checkVerifyCode = (str) => {
    return REGEXP_MAVEN.verifyCode.test(str);
};
// 检测金额
export const checkPrice = (str) => {
    return REGEXP_MAVEN.price.test(str);
};

// 验证正整数含0
export const checkPositiveIntegerZero = (str) => {
    const reg = /^\+?(0|[1-9][0-9]*)$/;
    return reg.test(str);
};

// 验证数字
export const checkNumber = (str) => {
    const reg = /^[0-9]*$/;
    return reg.test(str);
};

// 验证正整数
export const checkPositiveInteger = (str) => {
    const reg = /(^[1-9]\d*$)/;
    return reg.test(str);
};

// 验证IP
export const checkIp = (str) => {
    return REGEXP_MAVEN.ip.test(str);
};

// 验证域名
export const checkDomain = (str) => {
    return REGEXP_MAVEN.domain.test(str);
};
